ORG	1300H


RS232_TIME_AUX:		MOV	B,#10
			DIV	AB
			ADD	A,#'0'
			LCALL	RS232_WRITE_BYTE
			MOV	A,#0
			ADD	A,B
			ADD	A,#'0'
			LCALL	RS232_WRITE_BYTE
			RET


	
RS232_WRITE_BYTE:

		JNB	RS232_TRANS_READY,$
		MOV	SBUF,A
		CLR	RS232_TRANS_READY
		RET	
	

	
RS232_WRITE_TIME:	MOV	A,CLK_HORAS
			LCALL	RS232_TIME_AUX
			MOV	A,#':'
			LCALL	RS232_WRITE_BYTE
			MOV	A,CLK_MIN
			LCALL	RS232_TIME_AUX
			MOV	A,#':'
			LCALL	RS232_WRITE_BYTE
			MOV	A,CLK_SEG
			LCALL	RS232_TIME_AUX
			RET

	
RS232_WRITE_TESTIGOS:	JNB	LUZ_01,RS232_WT_01
			MOV	A,#'1'
			LCALL	RS232_WRITE_BYTE
			LJMP	RS232_WT_02
RS232_WT_01:		MOV	A,#'0'
			LCALL	RS232_WRITE_BYTE
	
	
RS232_WT_02:		JNB	LUZ_02,RS232_WT_03
			MOV	A,#'1'
			LCALL	RS232_WRITE_BYTE
			LJMP	RS232_WT_04
RS232_WT_03:		MOV	A,#'0'
			LCALL	RS232_WRITE_BYTE
		
RS232_WT_04:		RET

RS232_WRITE_ALARMA:		
			MOV	A,ALARMA_HORA
			LCALL   RS232_TIME_AUX
			MOV	A,#':'
			LCALL	RS232_WRITE_BYTE
			
			MOV	A,ALARMA_MINUTO
			LCALL	RS232_TIME_AUX
			MOV	A,#' '
			LCALL	RS232_WRITE_BYTE
			
RS232_WA_01:		JNB	ALARMA_MOTOR_01,RS232_WA_01_OFF
			MOV	A,#'1'
			LCALL	RS232_WRITE_BYTE
			
			LJMP	RS232_WA_02
RS232_WA_01_OFF:	MOV	A,#'0'
			LCALL	RS232_WRITE_BYTE
RS232_WA_02:		JNB	ALARMA_MOTOR_02,RS232_WA_02_OFF
			MOV	A,#'1'
			LCALL	RS232_WRITE_BYTE
			LJMP	RS232_WA_03
RS232_WA_02_OFF:	MOV	A,#'0'
			LCALL	RS232_WRITE_BYTE
RS232_WA_03:		JNB	ALARMA_LUZ_01,RS232_WA_03_OFF
			MOV	A,#'1'
			LCALL	RS232_WRITE_BYTE
			LJMP	RS232_WA_04
RS232_WA_03_OFF:	MOV	A,#'0'
			LCALL	RS232_WRITE_BYTE
RS232_WA_04:		JNB	ALARMA_LUZ_02,RS232_WA_04_OFF
			MOV	A,#'1'
			LCALL	RS232_WRITE_BYTE
			LJMP	RS232_WA_05
RS232_WA_04_OFF:	MOV	A,#'0'
			LCALL	RS232_WRITE_BYTE
RS232_WA_05:		JNB	ALARMA_STATUS,RS232_WA_OFF
RS232_WA_ON:		MOV	A,#'1'
			LCALL	RS232_WRITE_BYTE
			LJMP	RS232_WA_EXIT
RS232_WA_OFF:		MOV	A,#'0'
			LCALL	RS232_WRITE_BYTE
RS232_WA_EXIT:
			RET
	
	
RS232_REFRESH_MENU:	; PUSH_STATE
			PUSH	ACC
			PUSH	PSW
			PUSH	DPH
			PUSH	DPL

	
			SETB	RS0
			CLR	RS1
	
			LCALL	MENU_MOV_VALIDO
			MOV	R0,#5
RS_MENU_INC:		INC	DPTR
			DJNZ	R0,RS_MENU_INC
			MOV	R1,#20
RS_MENU_BUC:		MOV	A,#0		
			MOVC	A,@A+DPTR
			LCALL	RS232_WRITE_BYTE
			INC	DPTR
			DJNZ	R1,RS_MENU_BUC
			
			MOV	A,#' '
			LCALL	RS232_WRITE_BYTE
			
			LCALL	RS232_WRITE_TIME
			
			MOV	A,#' '	
			LCALL	RS232_WRITE_BYTE
			
			LCALL	RS232_WRITE_TESTIGOS	
							
			MOV	A,#' '
			LCALL	RS232_WRITE_BYTE

			lcall	RS232_WRITE_ALARMA
			MOV	A,#00Dh
			LCALL	RS232_WRITE_BYTE
			CLR	RS232_PEND_MENU 
			POP	DPL	
			POP	DPH
			POP	PSW
			POP	ACC
			; POP_STATE  
			RET

RS232_RECIVE_CHAR:	PUSH	ACC
			MOV	A,RS232_CHAR_REC
			CJNE	A,#036H,RS_RC_IZQDA
RS_RC_DCHA:		SETB	MENU_PEND
			SETB	MENU_PEND_RIGHT		
			LJMP	RS_RC_EXIT

RS_RC_IZQDA:		CJNE	A,#034H,RS_RC_UP
			SETB	MENU_PEND
			SETB	MENU_PEND_LEFT	
			LJMP	RS_RC_EXIT
	
RS_RC_UP:		CJNE	A,#038H,RS_RC_DOWN
			SETB	MENU_PEND
			SETB	MENU_PEND_UP	
			LJMP	RS_RC_EXIT

RS_RC_DOWN:		CJNE	A,#032H,RS_RC_ENTER
			SETB	MENU_PEND
			SETB	MENU_PEND_DOWN
			LJMP	RS_RC_EXIT

RS_RC_ENTER:		CJNE	A,#035H,RS_RC_UPDATE
			SETB	ACCION_PEND
			LJMP	RS_RC_EXIT
RS_RC_UPDATE:		CJNE	A,#030H,RS_RC_EXIT
			SETB	RS232_PEND_MENU
			LJMP	RS_RC_EXIT

		
RS_RC_EXIT:		CLR	RS232_REC_READY
			POP	ACC
			RET
